/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.dusa.worklog.viewer;

import cz.dusa.worklog.datalib.Customer;
import cz.dusa.worklog.datalib.Project;
import cz.dusa.worklog.datalib.WorklogData;

/**
 *
 * @author vdusa
 */
public class WorklogWindowManager {
    private static WorklogWindowManager instance = null;

    private WorklogWindowManager(){
    }

    public static WorklogWindowManager getInstance(){
        if(instance == null){
            instance = new WorklogWindowManager();
        }
        return instance;
    }

    public void openWindow(WorklogData wd){
        if (wd instanceof Customer){
            CustomerEditorTopComponent win = CustomerEditorTopComponent.findInstance((Customer)wd);
            win.open();
            win.requestActive();
            return;
        }

        if (wd instanceof Project){
            ProjectEditorTopComponent win = ProjectEditorTopComponent.findInstance((Project)wd);
            win.open();
            win.requestActive();
            return;
        }
    }

    void closeWindow(WorklogData wd) {
        if (wd instanceof Customer){
            CustomerEditorTopComponent win = CustomerEditorTopComponent.findInstance((Customer)wd);
            if (win.isOpened()){
                win.close();
            }
        }

        if (wd instanceof Project){
            ProjectEditorTopComponent win = ProjectEditorTopComponent.findInstance((Project)wd);
            if (win.isOpened()){
                win.close();
            }
        }
    }
}
